package pool

import (
	"strings"
	"sync"
)

// slicePointerPool 定义 *strings.Builder 复用池的类型
type stringBuilderPool sync.Pool

// NewStringBuilderPool 创建一个 *strings.Builder 复用池
func NewStringBuilderPool() *stringBuilderPool {
	return &stringBuilderPool{New: func() any { return new(strings.Builder) }}
}

// Alloc 分配一个 *strings.Builder 对象
func (own *stringBuilderPool) Alloc() *strings.Builder {
	return (*sync.Pool)(own).Get().(*strings.Builder)
}

// Dealloc 释放当前 *strings.Builder 对象
func (own *stringBuilderPool) Dealloc(obj *strings.Builder) {
	obj.Reset()
	(*sync.Pool)(own).Put(obj)
}
